package net.butfly.bus.server.config;

import java.util.Map;
import java.util.Map.Entry;

import net.butfly.bus.config.Config;
import net.butfly.bus.server.config.bean.RouterBean;
import net.butfly.bus.server.config.bean.TxBean;
import net.butfly.bus.util.TXUtils;

public class ServerConfig extends Config {
	private Map<String, TxBean> txMap;
	private RouterBean router;
	private String busID;

	public void setBusID(String busID) {
		this.busID = busID;
	}

	public String getBusID() {
		return busID;
	}

	public RouterBean getRouterBean() {
		return router;
	}

	public String[] getNodeIDsByMatching(String txCode) {
		if (txMap != null) {
			for (Entry<String, TxBean> et : txMap.entrySet()) {
				if (et.getValue().matching(txCode)) {
					return et.getValue().getNodeAry();
				}
			}
		}
		return null;
	}

	public TxBean getTxBean(String txCode, String versionNo) {
		return txMap != null ? txMap.get(TXUtils.key(txCode, versionNo)) : null;
	}

	public void setTxMap(Map<String, TxBean> txMap) {
		this.txMap = txMap;
	}

	public void setRouter(RouterBean router) {
		this.router = router;
	}
}
